AddCSLuaFile()

DEFINE_BASECLASS( "class_default" )

local PLAYER = {}

PLAYER.DisplayName			= "Man at Arms"

PLAYER.WalkSpeed = 200
PLAYER.MaxHealth			= 150
PLAYER.StartHealth			= 150

PLAYER.AttackSpeed = 2.2
PLAYER.WeaponDamageMin = 20
PLAYER.WeaponDamageMax = 35

PLAYER.MainhandModel = "models/weapons/w_shotgun.mdl"
PLAYER.OffhandModel = ""
PLAYER.MainHand = nil
PLAYER.OffHand = nil

PLAYER.Spells = {
	20,
	50,
	60,
	510,
	40
}

function PLAYER:SetupDataTables()

	BaseClass.SetupDataTables( self )

end

function PLAYER:Spawn()
	print("You have spawned as a warrior!")
	self.Player:SetWalkSpeed(self.WalkSpeed)
	self:Loadout()
	self:SetupGear()
	self:SetupSpells()
	self:SetupStats()
	net.Start("SendSelfMaxHealth")
	net.WriteFloat(self.MaxHealth)
	net.Send(self.Player)
	self.Player.SetHoldType = "crossbow"
end

function PLAYER:SetupStats()
	local weapon = self.Player:GetActiveWeapon()
		
	weapon.AttackSpeed = self.AttackSpeed
	weapon.MinWeaponDamage = self.WeaponDamageMin
	weapon.MaxWeaponDamage = self.WeaponDamageMax
	weapon.WeaponStance = "ranged"

end

function PLAYER:SetupGear()
	SetEquipped(self.Player, self.Player.tempEquippedItems)
end

function PLAYER:SetupSpells()
	if(self.Player.tempSpells == nil)then
		SetSpells(self.Player, self.Spells)
		timer.Simple(0.1, function()
			net.Start("SendPlayerSpells")
			net.WriteTable(self.Spells)
			net.Send(self.Player)
		end)
	end
end

function PLAYER:Loadout()
	self.MainHand = ents.Create("prop_dynamic")
	self.MainHand:SetModel(self.MainhandModel)
	self.MainHand:PhysicsInit(SOLID_VPHYSICS)
	self.MainHand:SetMoveType(MOVETYPE_NONE)
	self.MainHand:SetSolid( SOLID_VPHYSICS )
	self.MainHand:SetParent(self.Player)
	self.MainHand:AddEffects( EF_BONEMERGE )
	self.Player:SetNWEntity("MainWep", self.MainHand)
	self.OffHand = ents.Create("prop_physics")
	self.OffHand:SetModel(self.OffhandModel)
	self.OffHand:PhysicsInit(SOLID_VPHYSICS)
	self.OffHand:SetMoveType(MOVETYPE_NONE)
	self.OffHand:SetSolid( SOLID_VPHYSICS )
	self.OffHand:SetParent(self.Player)
	self.OffHand:AddEffects( EF_BONEMERGE )
	self.Player:SetNWEntity("OffWep", self.OffHand)
	self.Player:Give( "weapon_all" )
end

function PLAYER:OnHit(target)
	target:EmitSound("devin/blackbetty/weapons/2HMaceHitPlateCrit.wav", 150, 100+math.random(-10,-30))
	target:SetVelocity((((self.Player:GetPos()) - target:GetPos())*-9))
	ParticleEffect( "pummel_hit", target:GetPos() + Vector(0, 0, 46) + (target:GetAngles():Forward()*7), Angle(0,0,0), target )
	
end
	
player_manager.RegisterClass( "class_gunslinger", PLAYER, "class_default" )